package com.ken.expresskotlin.activity

import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.ImageView
import androidx.databinding.DataBindingUtil
import com.ken.expresskotlin.R
import com.ken.expresskotlin.databinding.ActivityMainBinding
import com.youth.banner.BannerConfig
import com.youth.banner.Transformer
import com.youth.banner.loader.ImageLoader
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {


    companion object {
        const val TAG: String = "MainActivity"
    }

    //    播放本地图片
    private val arrayOfImg =
        arrayListOf(
            R.mipmap.banner1,
            R.mipmap.banner2,
            R.mipmap.banner3,
            R.mipmap.banner4
        )

    //    文字
    private val arrayTitle = arrayListOf("轮播图片1", "轮播图片2", "轮播图片3", "轮播图片4")


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val dataBindingUtil =
            DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main)

        initData()
    }


    fun initData() {
        banner.setImages(arrayOfImg)
            .setDelayTime(3000)
            .isAutoPlay(true)
            .setBannerTitles(arrayTitle)
            .setImageLoader(object : ImageLoader() {
                override fun displayImage(context: Context?, path: Any?, imageView: ImageView?) {
                    imageView?.setImageResource(path as Int)
                }
            }).setIndicatorGravity(BannerConfig.CENTER)
            .setBannerAnimation(Transformer.Default)
            .setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE)
            .setOnBannerListener { position: Int ->
                run {
                    //                    println(TAG)
                    Log.e(TAG, "点击图片$position")

                }
            }
            .start()

    }


}
